<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增系统弹窗')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: jasny-bootstrap-css"/>
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-appnotice-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">应用：</label>
            <div class="col-sm-8">
                <select name="app" class="form-control m-b" th:with="type=${@dict.getType('storage_app_type')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片：</label>
            <div class="col-sm-8">
                <input id=img name="img" class="form-control" type="hidden">
                <div class="fileinput fileinput-new" data-provides="fileinput">
                    <div class="fileinput-new thumbnail" style="width:180px; height: 320px;">
                        <img>
                    </div>
                    <div class="fileinput-preview fileinput-exists thumbnail"
                         style="max-width: 180px; max-height: 320px;"></div>
                    <div>
                        <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span
                                class="fileinput-exists">更改</span><input type="file" class="image"></span>
                        <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">内容：</label>
            <div class="col-sm-8">
                <textarea name="content" rows="7" class="form-control"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">跳转类型：</label>
            <div class="col-sm-8">
                <select name="targetType" class="form-control m-b"
                        th:with="type=${@dict.getType('app_notice_target_type')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">跳转URL：</label>
            <div class="col-sm-8">
                <input name="targetUrl" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">弹窗次数：</label>
            <div class="col-sm-8">
                <input name="promptCount" class="form-control" type="text" value="1" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">弹窗间隔天数：</label>
            <div class="col-sm-8">
                <select name="promptIntervalDay" class="form-control m-b"
                        th:with="type=${@dict.getType('prompt_interval_day')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">开始时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="startTime" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text" required>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">结束时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="endTime" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text" required>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('common_status')}">
                    <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}"
                           th:checked="${dict.default}">
                    <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否灰度：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('common_support')}">
                    <input type="radio" th:id="${'grey_' + dict.dictCode}" name="grey" th:value="${dict.dictValue}"
                           th:checked="${dict.default}">
                    <label th:for="${'grey_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">灰度分桶：</label>
            <div class="col-sm-8">
                <select id="greyIdxs" class="form-control select2-multiple" multiple>
                    <option th:each="greyIdx:${greyIdxs}" th:value="${greyIdx.idx}" th:text="${greyIdx.idx}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否指定渠道：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('common_support')}">
                    <input type="radio" th:id="${'channelOpen_' + dict.dictCode}" name="channelOpen"
                           th:value="${dict.dictValue}" th:checked="${dict.default}">
                    <label th:for="${'channelOpen_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">指定渠道列表：</label>
            <div class="col-sm-8">
                <select id="channels" class="form-control select2-multiple" multiple>
                    <option th:each="channel:${channels}" th:value="${channel.channelId}" th:text="${channel.name}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">指定版本：</label>
            <div class="col-sm-8">
                <input name="version" class="form-control" type="text" placeholder="指定等于这个版本才弹">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">最大版本：</label>
            <div class="col-sm-8">
                <input name="maxVersion" class="form-control" type="text" placeholder="指定小于等于这某个版本才弹">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: jasny-bootstrap-js"/>
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
        var prefix = ctx + "common/appnotice"
        $("#form-appnotice-add").validate({
            focusCleanup: true
        });

        $('.image').on('change.bs.fileinput', function (e) {
        	var file = $(this)[0].files[0];
        	var data = new FormData();
	        data.append("file", file);
	        $.ajax({
	            type: "POST",
	            url: ctx + "common/uploadOSS",
	            data: data,
	            cache: false,
	            contentType: false,
	            processData: false,
	            dataType: 'json',
	            success: function(result) {
	            	$('#img').val(result.url);
	            	$.modal.alertSuccess("图片上传成功");
	            },
	            error: function(error) {
	                alert("图片上传失败。");
	            }
	        });

        });

        function submitHandler() {
            if ($.validate.form()) {
                let data = $('#form-appnotice-add').serializeArray()
                let greyIdxs = $.form.selectSelects("greyIdxs")
                data.push({"name": "greyIdxs", "value": greyIdxs});
                let channels = $.form.selectSelects("channels")
                data.push({"name": "channels", "value": channels});
                $.operate.save(prefix + "/add", data);
            }
        }

        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd hh:ii:00",
            autoclose: true
        });

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd hh:ii:00",
            autoclose: true
        });



</script>
</body>
</html>